import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/', redirect: '/home',
    component: Home
  },

  {
    path: '/home',
    name: 'Home',
    component: Home,
    children: [
      // 首页
      {
        path: '/home',
        meta:{
          KeepAlvie:true
        },
        component: () => import(/* webpackChunkName: "home" */ '../views/HomeChlid/HomeBody.vue')
      },
      // 分类
      {
        path: '/browse',
        component: () => import(/* webpackChunkName: "browse" */ '../views/HomeChlid/Browse.vue')
      },
      // 排行榜
      {
        path: '/rankings',
        meta:{
          KeepAlvie:true
        },
        component: () => import(/* webpackChunkName: "rankings" */ '../views/HomeChlid/Rankings.vue')
      },
      // 漫画页面
      {
        path: '/comics',
        meta:{
          KeepAlvie:true
        },
        component: () => import(/* webpackChunkName: "rankings" */ '../views/HomeChlid/HomeBody.vue')
      },
      // 漫画阅读器
      {
        path: '/comicreader',
        component: () => import(/* webpackChunkName: "comicreader" */ '../views/HomeChlid/ComicReader.vue')
      },
      {
        path: '/update',
        component: () => import(/* webpackChunkName: "update" */ '../views/HomeChlid/Update.vue')
      },
      {
        path: '/history',
        component: () => import(/* webpackChunkName: "history" */ '../views/HomeChlid/History.vue')
      },
      {
        meta: 1,
        path: '/following',
        component: () => import(/* webpackChunkName: "following" */ '../views/HomeChlid/Following.vue')
      },
      {
        path: '/bookdetails',
        component: () => import(/* webpackChunkName: "bookdetails" */ '../views/HomeChlid/BookDetails.vue')
      },
      {
        path: '/aboutus',
        component: () => import(/* webpackChunkName: "aboutus" */ '../views/HomeChlid/AboutUs.vue')
      },
      {
        path: '/contactdreame',
        component: () => import(/* webpackChunkName: "contactdreame" */ '../views/HomeChlid/ContactDreame.vue')
      },
      {
        path: '/reader',
        component: () => import(/* webpackChunkName: "reader" */ '../views/HomeChlid/Reader.vue')
      },
      {
        path: '/policy',
        component: () => import(/* webpackChunkName: "reader" */ '../views/HomeChlid/FootChild/PrivacyPolicy.vue')
      },
      {
        path: '/qa',
        component: () => import(/* webpackChunkName: "reader" */ '../views/HomeChlid/FootChild/QA.vue')
      },
      {
        path: '/ofuse',
        component: () => import(/* webpackChunkName: "reader" */ '../views/HomeChlid/FootChild/Ofuse.vue')
      },
    ]
  },
  // {
  //   path: '/about',
  //   name: 'About',
  //   // route level code-splitting
  //   // this generates a separate chunk (about.[hash].js) for this route
  //   // which is lazy-loaded when the route is visited.
  //   component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
  // }
]

const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
  return originalPush.call(this, location).catch(err => err)
}


const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

// 路由切换回归顶部
router.afterEach((to, from, next) => {
  window.scrollTo(0, 0);
});


export default router
